/*
 * @lc app=leetcode.cn id=819 lang=typescript
 *
 * [819] 最常见的单词
 */

// @lc code=start
function mostCommonWord(paragraph: string, banned: string[]): string {
    let cache = new Map<string, number>();
    paragraph.split(/\s|!|\?|'|,|;|\./g).forEach((i) => {
        i = i.toLowerCase();
        if (i !== "" && !banned.includes(i)) {
            cache.set(i, (cache.get(i) || 0) + 1);
        }
    });
    let max = 0;
    let final = "";
    for (const [key, val] of cache.entries()) {
        if (val > max) {
            final = key;
            max = val;
        }
    }
    return final;
}
// @lc code=end
